package lc;

import java.util.HashSet;
import java.util.Set;

public class Q202 {

    public boolean isHappy(int n) {
        Set<Integer> store = new HashSet<>();
        while (n != 1) {
            if (store.contains(n)) {
                return false;
            }
            store.add(n);
            int k = 0;
            while (n != 0) {
                final int i = n % 10;
                k += i * i;
                n = n / 10;
            }
            n = k;
        }
        return true;
    }

    public static void main(String[] args) {
        final Q202 q202 = new Q202();
        final boolean happy = q202.isHappy(19);
        System.out.println(happy);
    }

}
